package com.example.controller;

import com.example.pojo.Activity;
import com.example.service.ActivityService;
import com.example.utils.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(value = "活动管理接口")
@RequestMapping("/activity")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    //添加活动
    @PostMapping
    public Result add(@RequestBody Activity activity){
        activityService.add(activity);
        return Result.success();
    }
    //根据状态查询活动
    @GetMapping
    public Result query(@RequestParam String status){
        List<Activity> activity = activityService.query(status);
        return Result.success(activity);
    }
    //根据id查询活动
    @GetMapping("/{id}")
    public Result queryById(@PathVariable Integer id){
        Activity activity = activityService.query(id);
        return Result.success(activity);
    }

    //修改编辑活动
    @PutMapping
    public Result update(@RequestBody Activity activity){

        activityService.update(activity);
        return Result.success();
    }

    //活动发布
    @PostMapping("/{id}")
    public Result publish(@PathVariable Integer id){
        activityService.publishActivity(id);
        return Result.success();

    }
}
